package com.nado.iims2.blog.dao.service;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.nado.extensions.sql.SimpleSqlMapDaoSupport;
import com.nado.iims2.blog.model.service.Banner;
import com.nado.iims2.blog.model.service.BannerThema;

@Repository("BannerDAO")
public class BannerDAOImpl extends SimpleSqlMapDaoSupport implements BannerDAO {
	/** The Constant PREFIX. */
	private final static String PREFIX = "com.nado.iims2.blog.banner.";
	
	@Override
	public List<BannerThema> selectBannerThemaList() throws SQLException {
		return getSqlMapClient().queryForList(PREFIX + "selectBannerThemaList");
	}

	@Override
	public List<Banner> selectBannerList(int bnnrThmSeq, String progressYn, int offset, int count) throws SQLException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("bnnrThmSeq", bnnrThmSeq);
		params.put("progressYn", progressYn);
		params.put("offset", offset);
		params.put("count", count);
		
		return getSqlMapClient().queryForList(PREFIX + "selectBannerList", params);
	}

	@Override
	public int selectBannerListCount(int bnnrThmSeq, String progressYn) throws SQLException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("bnnrThmSeq", bnnrThmSeq);
		params.put("progressYn", progressYn);
		
		return (Integer) getSqlMapClient().queryForObject(PREFIX + "selectBannerListCount", params);
	}

	@Override
	public Banner selectBannerDetail(int bnnrSeq) throws SQLException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("bnnrSeq", bnnrSeq);
		
		return (Banner) getSqlMapClient().queryForObject(PREFIX + "selectBannerDetail", params);
	}

	@Override
	public List<Banner> selectBannerOrderList(int bnnrThmSeq) throws SQLException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("bnnrThmSeq", bnnrThmSeq);
		
		return getSqlMapClient().queryForList(PREFIX + "selectBannerOrderList", params);
	}

	@Override
	public int selectMaxBannerOrder(int bnnrThmSeq) throws SQLException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("bnnrThmSeq", bnnrThmSeq);
		
		return (Integer) getSqlMapClient().queryForObject(PREFIX + "selectMaxBannerOrder", params);
	}

	@Override
	public BannerThema selectBannerThemaByNo(int bnnrThmSeq) throws SQLException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("bnnrThmSeq", bnnrThmSeq);
		
		return (BannerThema) getSqlMapClient().queryForObject(PREFIX + "selectBannerThemaByNo", params);
	}

}
